//
//  ByUserMyRecordDetailVC.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/15.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByUserMyRecordDetailVC.h"
// model
#import "ByModelUserMyDotorsRecord.h"

@interface ByUserMyRecordDetailVC ()
@property (nonatomic, strong) UIScrollView *scroll;
@property (nonatomic, strong) NSMutableArray *dataAry;
@end

@implementation ByUserMyRecordDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBackBarButtonItem];
    [self fetchData];
}
#pragma mark - getter
- (UIScrollView *)scroll{
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] init];
        [self.view addSubview:_scroll];
        [_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(0));
            make.right.equalTo(@(0));
            if (@available(iOS 11.0,*)) {
                make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
                make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
            }else{
                make.top.equalTo(self.view.mas_top);
                make.bottom.equalTo(self.view.mas_bottom);
            }
        }];
        _scroll.bounces = NO;
        _scroll.showsHorizontalScrollIndicator = NO;
    }
    return _scroll;
}

- (NSMutableArray *)dataAry{
    if (!_dataAry) {
        _dataAry = [NSMutableArray array];
    }
    return _dataAry;
}

#pragma mark -  fetch data
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelUserMyDotorsRecord *model = [[ByModelUserMyDotorsRecord alloc] init];
        model.create_time = @"2016-6-7";
        model.content = @"测试测是束带结发获得手机国服的就是公费是动画覅看还是点击挂号结束该回复";
        [self.dataAry addObject:model];
    }
    [self createViews];
}

#pragma mark - create views
- (void)createViews{
    CGFloat y_offset = 30;
    for (int i = 0; i < self.dataAry.count; i ++) {
        CGFloat time_width = [@"2020-12-12" getSizeOfString:14].width + 5;
        CGFloat content_width = SCREEN_WIDTH - 10 * 4 - time_width - 15;
        ByModelUserMyDotorsRecord *model = self.dataAry[i];
        CGFloat content_height = [model.content getRectOfStringWithSize:
                                  CGSizeMake(content_width - 30, MAXFLOAT) font:14].size.height + 20;
        
        // 1.时间
        UILabel *timeLabel = [[UILabel alloc] init];
        [self.scroll addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(10));
            make.size.mas_equalTo(CGSizeMake(time_width, 20));
            make.top.equalTo(@(y_offset));
        }];
        timeLabel.font = FONT(14);
        
        // 2.圆圈
        UIImageView *img = [[UIImageView alloc] init];
        [self.scroll addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeLabel.mas_right).offset(10);
            make.top.equalTo(timeLabel.mas_top);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        img.backgroundColor = [UIColor whiteColor];
        img.layer.borderColor = BY_THEME_COLOR.CGColor;
        img.layer.cornerRadius = 15 / 2;
        img.layer.borderWidth = 3;
        
        // 3.线
        UIView *lineView = [[UIView alloc] init];
        [self.scroll addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(img.mas_bottom);
            make.left.equalTo(img.mas_left).offset(7.5);
            if (i == 0) {
                make.size.mas_equalTo(CGSizeMake(1, y_offset + content_height - 15));
            }else{
                make.size.mas_equalTo(CGSizeMake(1, y_offset - 15));
            }
        }];
        lineView.backgroundColor = [UIColor blackColor];
        // 4.背景图片
        //        UIImageView *imgBg = [[UIImageView alloc] init];
        //        [self.scroll addSubview:imgBg];
        
        
        // 4.内容
        UIImageView *contentView = [[UIImageView alloc] init];
        [self.scroll addSubview:contentView];
        //        contentView.image = [UIImage imageNamed:@"My_record"];
        UIImage *imgLogin = [UIImage imageNamed:@"My_record"];
        imgLogin = [imgLogin stretchableImageWithLeftCapWidth:floorf(imgLogin.size.width - 10) topCapHeight:floorf(imgLogin.size.height  - 10)];
        contentView.image = imgLogin;
        
        
        UILabel *contentLabel = [[UILabel alloc] init];
        contentLabel.numberOfLines = 0;
        [self.scroll addSubview:contentLabel];
        [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(img.mas_right).offset(20);
            make.size.mas_equalTo(CGSizeMake(content_width - 30, content_height));
            make.top.equalTo(@(y_offset));
        }];
        contentLabel.font = FONT(14);
        
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(img.mas_right);
            make.top.equalTo(@(y_offset));
            make.width.equalTo(@(content_width));
            make.bottom.equalTo(contentLabel.mas_bottom);
        }];
        
        // 测试数据
        contentLabel.text = model.content;
        timeLabel.text = model.create_time;
        
        
        y_offset += content_height + 30;
        
    }
    
    UILabel *lastView = self.scroll.subviews.lastObject;
    UIView *footerView = [[UIView alloc] init];
    [self.scroll addSubview:footerView];
    [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(lastView.mas_bottom);
        make.right.equalTo(@(0));
        make.bottom.equalTo(self.scroll.mas_bottom);
    }];
    
    
    
}



@end
